package com.moji.controller.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.moji.common.base.ApiResult;
import com.moji.entity.MjProductPurchase;
import com.moji.entity.dto.QueryProductPurchaseDto;
import com.moji.service.MjProductPurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 产品选购配置表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2024-08-13
 */
@RestController
@RequestMapping("web/auth/mjProductPurchase")
@Api(tags = "产品选购web相关接口(控制中心)", value = "产品选购web相关接口(控制中心)")
public class MjProductPurchaseController {

    @Resource
    private MjProductPurchaseService mjProductPurchaseService;

    @PostMapping("/queryByPage")
    @ApiOperation(value = "产品选购属性列表")
    public ApiResult<List<List<MjProductPurchase>>> queryByPage(){
        List<List<MjProductPurchase>> listArrayList=new ArrayList<>();
        LambdaQueryWrapper<MjProductPurchase> wrapper = new LambdaQueryWrapper<>();
        //标题
        //根据标题返回集合
        wrapper.select(MjProductPurchase::getCode).groupBy(MjProductPurchase::getCode);
        List<MjProductPurchase> list = mjProductPurchaseService.list(wrapper);
        for (int i = 0; i <list.size(); i++) {
            LambdaQueryWrapper<MjProductPurchase> wrapper1 = new LambdaQueryWrapper<>();
            //标题
            //根据标题返回集合
            wrapper1.eq(MjProductPurchase::getCode,list.get(i).getCode());
            wrapper1.orderByAsc(MjProductPurchase::getSort);
            wrapper1.eq(MjProductPurchase::getStatus,0);
            wrapper1.orderByDesc(MjProductPurchase::getUpdateTime);
            List<MjProductPurchase> list1 = mjProductPurchaseService.list(wrapper1);
            listArrayList.add(list1);
        }
        return ApiResult.ok(listArrayList);
    }

    @PostMapping("/detail")
    @ApiOperation(value = "产品选购_详情",response = MjProductPurchase.class)
    public ApiResult detail(@RequestParam("id") Long id){
        return ApiResult.ok(mjProductPurchaseService.detail(id));
    }

}

